package com.box.modules.job.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.box.modules.report.entity.BoxRowDataEntity;
import com.box.modules.report.service.BoxRowDataService;
import com.box.modules.report.service.BoxRowProcessedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yangjs
 * @email catalpa65@163.com
 * @date 2020-10-29
 */
@Component("rowDataTask")
public class RowDataTask implements ITask {

    @Autowired
    BoxRowProcessedService boxRowProcessedService;

    @Autowired
    BoxRowDataService boxRowDataService;

    @Override
    public void run(String params) {
        LambdaQueryWrapper<BoxRowDataEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BoxRowDataEntity::getRemark, "0");

        //所有未解析的数据
        List<BoxRowDataEntity> boxRowDataEntityList = boxRowDataService.list(queryWrapper);
        for (BoxRowDataEntity one : boxRowDataEntityList) {
            //插入成功修改原始数据标识
            if (boxRowProcessedService.addRowProcessed(one)) {
                one.setRemark("1");
                boxRowDataService.updateById(one);
            }
        }
    }
}
